#!/bin/sh
#
# Start the named (DNS) server daemon
#  

start() {
    echo -n "Starting DNS Services: "
    if [ -n "`/opt/bin/pidof named`" ]; then
	echo "already running..."
	false; 
	return
    fi
    cd /opt/etc/named
    /opt/sbin/named -c /opt/etc/named/named.conf 
    echo "started"
    return
}
stop() {
    echo "Shutting down DNS Services: "
    /opt/sbin/rndc -s 127.0.0.1 stop
    sleep 5
    if [ -n "`/opt/bin/pidof named`" ]; then
        echo -n "Failed, killing process"
	/opt/bin/killall named 2>/dev/null
    fi
    return
}
bindstatus() {
    /opt/sbin/rndc -s 127.0.0.1 status
    return
}
restart() {
    stop
    start
}

case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  status)
	bindstatus
	;;
  restart|reload)
	restart
	;;
  condrestart)
	[ -n "`/opt/bin/pidof named`" ] && restart
	;;
  *)
	echo "Usage: $0 {start|stop|status|restart|condrestart}"
	exit 1
esac
exit $?
